package testooj3.domain;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import testooj3.compatibility.InterfacesCompatibilityChecker;

/**
 * @author  andres
 */
@SuppressWarnings("serial")


public class TParameter implements java.io.Serializable
{
    String mTipo;
    Vector mTestValues;
    String mNobre;
    List<String> mCampos; 
	public String getMNombre() {
		return mNobre;
	}


	public void setMNombre(String mName) {
		this.mNobre = mName;
		this.mCampos =  new ArrayList<String>();
	}

	private int numberOfRandomTestValues;
	private boolean useValuesAsDescribed;
	
		
	
    public TParameter(Class tipo) {
        mTipo=tipo.getName();
        mTestValues=new Vector();
		this.mCampos =  new ArrayList<String>();
    }
    
    
    public TParameter(Class tipo, String parValue){
    	mTipo = tipo.getName();
    	mTestValues = new Vector();
    	mTestValues.add(parValue);
		this.mCampos =  new ArrayList<String>();
    }
    
    public TParameter(Class tipo, String parValue, String name){
    	mTipo=tipo.getName();
    	mNobre=name;    	
    	if(parValue.isEmpty())
            mTestValues=new Vector();
    	else
        	mTestValues.add(parValue);
    	this.mCampos =  new ArrayList<String>();
    }
    
    public List<String> getMCampos()
    {
    	return mCampos;
    }
    public boolean equals(Object o) {
    	if (!(o instanceof TParameter)) return false;
    	TParameter auxi=(TParameter) o;
    	//return (auxi.mTipo.equals(this.mTipo));
    	if (auxi.mTipo.equals(this.mTipo) && auxi.mTestValues.equals(this.mTestValues))
    		return true;
    	else return false;
    }
    
    public void setTipo(String tipo) {
        if (tipo.startsWith ("[F")){
            tipo=tipo.concat ("Float;");
        }else if (tipo.startsWith ("[D")){
            tipo=tipo.concat ("Double;");
        }else if (tipo.startsWith ("[I")){
            tipo=tipo.concat ("Integer;");
        }else if (tipo.startsWith ("[C")){
            tipo=tipo.concat ("Character;");
        }else if (tipo.startsWith ("[J")){
            tipo=tipo.concat ("Long;");
        }else if (tipo.startsWith ("[S")){
            tipo=tipo.concat ("Short;");
        }else if (tipo.startsWith ("[B")){
            tipo=tipo.concat ("Byte;");
        }else if (tipo.equalsIgnoreCase ("[Ljava.lang.string;")){
            tipo=tipo.concat ("String;");
        }
        this.mTipo=tipo;
    }
    
  
    
    public String getTipo() {
        if (mTipo.endsWith (";")){
            if (mTipo.equalsIgnoreCase ("float")){
            }else if (mTipo.equalsIgnoreCase ("double")){
            }else if (mTipo.equalsIgnoreCase ("Integer")){
            }else if (mTipo.equalsIgnoreCase ("Character")){
            }else if (mTipo.equalsIgnoreCase ("long")){
            }else if (mTipo.equalsIgnoreCase ("short")){
            }else if (mTipo.equalsIgnoreCase ("byte")){
            } else {
			}
        } else {
		}
        
        return mTipo;
    }
    
    
    
    public String toString() 
    {
        return mTipo;
    }	
    
    public void removeTestValue(int pos) 
    {
        this.mTestValues.remove(pos);
    }
    
     
    public void addTestValues(Vector values) 
    {
        for (int i=0; i<values.size(); i++) 
        {
            mTestValues.add(values.elementAt(i));
        }
    }
    
    
    
   
    
  
    /**
     * @return
     */

    
    protected TParameter() {
        this.mTestValues=new Vector();
    }

	public void setNumberOfRandomTestValues(int valor) {
		this.numberOfRandomTestValues=valor;
	}

	public int getNumberOfRandomTestValues() {
		return numberOfRandomTestValues;
	}

	public boolean useValuesAsDescribed() {
		return this.useValuesAsDescribed;
	}

	public void useValuesAsDescribed(boolean b) {
		this.useValuesAsDescribed=b;
	}
	
	
	public Object getTestValue(){
		return mTestValues.elementAt(0);
	}
	
	private boolean isSubstringEqName(String c1MethName, String c2MethName) {
		Vector name1Vector = getSubstringsVector(c1MethName);
		Vector name2Vector = getSubstringsVector(c2MethName);
		boolean found = false;
		int i = 0;
		while (!found && i<name2Vector.size()) {
			if (name1Vector.contains(name2Vector.get(i)))  
					found = true;
			i += 1;
		}
		return found;
	}	

	private Vector getSubstringsVector(String palabra) {
		Vector palabras = new Vector();
		String subPalabra="";
		for(int i=0; i< palabra.length();i++){
			subPalabra=subPalabra + Character.toLowerCase(palabra.charAt(i));
			if ((i+1)<palabra.length() && Character.isUpperCase(palabra.charAt(i+1))){
				palabras.add(subPalabra);
				subPalabra="";
			}
		}
		palabras.add(subPalabra);
		return palabras;
	}
	
	public void addCampos(Field[] fields) {
	
		for(Field field: fields)
			mCampos.add(field.getName());
	}




}
